//
//  ModelQues.m
//  解压缩&解析数据
//
//  Created by 盛超 on 2018/8/21.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "LSModelQues.h"

@implementation LSModelQues

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
             @"ImportantZSD":[LSZSD class],
             @"MainZSD":[LSZSD class],
             @"AudioList":[LSAVdio class],
             @"VedioList":[LSAVdio class],
             @"ChildList":[LSChild class]
             };
}

- (instancetype)initWithDict:(NSDictionary *)dict Type:(LSQuestionType)type AddressPath:(NSString*)path {
    if (self = [super init]) {
        
        if (dict!=nil) {
            //听力题
            if (type==LSListeningTest) {
                
                self.QuesBody = dict[@"QuesStem"][@"question"][@"DisplayContent"];
                
                LSAVdio *audio = [[LSAVdio alloc] init];
                audio.AudioPath = dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"__text"];
                if (audio.AudioPath!=nil && ![audio.AudioPath isEqualToString:@""]) {
                    audio.AudioPath = [NSString stringWithFormat:@"%@%@",path,audio.AudioPath];
                }
                audio.Article = dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"_Text"];
                
                self.AudioList = [NSArray arrayWithObject:audio];
                self.TimeLong = ((NSNumber*)dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"_length"]).integerValue;
                
                NSMutableArray *arr = [NSMutableArray array];
                NSMutableArray *childArr ;//= [NSMutableArray array];
                id obj = dict[@"QuesArray"][@"question"];
                if ([obj isKindOfClass:[NSArray class]]) {
                    childArr = [NSMutableArray arrayWithArray:dict[@"QuesArray"][@"question"]];
                } else {
                    childArr = [NSMutableArray arrayWithObject:dict[@"QuesArray"][@"question"]];
                }
                for (NSInteger i = 0; i<childArr.count; i++) {
                    LSChild *child = [[LSChild alloc] init];
                    NSDictionary *childDict = childArr[i];
                    child.ChildIndex = i+1;
                    child.ChildAnswerType = 1;
                    child.ChildAsk = childDict[@"issure"];
                    child.ChildAnswer = childDict[@"Answer"][@"Resource"][@"__text"];
                    child.ChildAnalyze = childDict[@"Analysis"][@"Resource"][@"__text"];
                    
                    NSMutableArray *arr2 = [NSMutableArray array];
                    NSArray *optinArr = childDict[@"option"];
                    for (NSInteger j = 0; j<optinArr.count; j++) {
                        LSOption *option = [[LSOption alloc] init];
                        NSDictionary *optionDict = optinArr[j];
                        option.OptionIndex = [NSString stringWithFormat:@"%c",(int)(j+65)];
                        if (optionDict[@"optxt"] == nil) {
                            option.OptionContent = @"";
                        } else {
                            option.OptionContent = optionDict[@"optxt"] ;
                        }
                        NSString *imgPath = [NSString stringWithFormat:@"%@%@",path,optionDict[@"picture"]];
                        option.OptionPicture = imgPath;
                        [arr2 addObject:option];
                    }
                    child.ChildOptionList = [NSArray arrayWithArray:arr2];
                    [arr addObject:child];
                }
                self.ChildList = [NSArray arrayWithArray:arr];
                self.TotalItemCount = self.ChildList.count;
                //        NSString *tring =  [ques yy_modelToJSONString];
                //        NSLog(@"%@",tring);
                
            } else if (type == LSReadingTest) { //朗读题
                
                self.QuesBody = dict[@"QuesArray"][@"question"][@"DisplayContent"];
                LSChild *child = [[LSChild alloc] init];
                child.ChildIndex = 1;
                child.ChildAnswer = dict[@"QuesArray"][@"question"][@"Answer"][@"Resource"][@"__text"];
                child.ChildAnalyze = dict[@"QuesArray"][@"question"][@"Analysis"][@"Resource"][@"__text"];
                self.ChildList = [NSArray arrayWithObject:child];
                self.TotalItemCount = 1;
                
                LSAVdio *audio = [[LSAVdio alloc] init];
                audio.AudioPath = dict[@"QuesArray"][@"question"][@"Audio"][@"Resource"][@"__text"];
                if (audio.AudioPath!=nil && ![audio.AudioPath isEqualToString:@""]) {
                    audio.AudioPath = [NSString stringWithFormat:@"%@%@",path,audio.AudioPath];
                }
                audio.Article = dict[@"QuesArray"][@"question"][@"Audio"][@"Resource"][@"_Text"];
                self.AudioList = [NSArray arrayWithObject:audio];
                
                //        NSString *tring =  [ques yy_modelToJSONString];
                //        NSLog(@"%@",tring);
                
            } else if (type == LSFollowSpeakingTest) {  //跟读题
                
                self.QuesBody = dict[@"QuesArray"][@"question"][@"DisplayContent"];
                
                LSChild *child = [[LSChild alloc] init];
                child.ChildIndex = 1;
                child.ChildAnswer = dict[@"QuesArray"][@"question"][@"Answer"][@"Resource"][@"__text"];
                child.ChildAnalyze = dict[@"QuesArray"][@"question"][@"Analysis"][@"Resource"][@"__text"];
                self.ChildList = [NSArray arrayWithObject:child];
                self.TotalItemCount = 1;
                
                LSAVdio *audio = [[LSAVdio alloc] init];
                audio.AudioPath = dict[@"QuesArray"][@"question"][@"Audio"][@"Resource"][@"__text"];
                if (audio.AudioPath!=nil && ![audio.AudioPath isEqualToString:@""]) {
                    audio.AudioPath = [NSString stringWithFormat:@"%@%@",path,audio.AudioPath];
                }
                audio.Article = dict[@"QuesArray"][@"question"][@"Audio"][@"Resource"][@"_Text"];
                self.AudioList = [NSArray arrayWithObject:audio];
                self.TimeLong = ((NSNumber*)dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"_length"]).integerValue;
                
                //        NSString *tring =  [ques yy_modelToJSONString];
                //        NSLog(@"%@",tring);
            }
            
        }
    }
    return self;
}


@end

@implementation LSZSD

@end

@implementation LSAVdio

@end

@implementation LSChild

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
             @"ChildStemList":[LSStem class],
             @"ChildOptionList":[LSOption class],
             };
}

@end

@implementation LSStem

@end

@implementation LSOption

@end


